package com.bana.sys.controller;

import com.bana.sys.dao.SocketLogDAO;
import com.bana.sys.dao.SystemLogDAO;
import com.bana.sys.model.*;
import com.bana.sys.utils.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 日志管理
 */
@RestController
@RequestMapping(value="/log" , method = RequestMethod.POST)
public class LogController {


    @Resource
    private SocketLogDAO socketLogDAO;

    @Resource
    private SystemLogDAO systemLogDAO;


    /**
     * 查询系统日志集合
     * @param request
     * @return
     */
    @RequestMapping(value = "/getSystemLogs.do", method = RequestMethod.POST)
    public PageResponse<SystemLog> getSystemLogs(@RequestBody TokenRequest<LogPageParameter> request) {

        LogPageParameter parameter=request.getData();
        List<SystemLog> logs=systemLogDAO.getLogs(parameter);
        int count=systemLogDAO.getLogCount(parameter);
        return new PageResponse<>(logs,count);
    }

    /**
     * 查询操作日志集合
     * @param request
     * @return
     */
    @RequestMapping(value = "/getSocketLogs.do", method = RequestMethod.POST)
    public PageResponse<SocketLog> getSocketLogs(@RequestBody TokenRequest<LogPageParameter> request) {

        LogPageParameter parameter=request.getData();
        if(parameter.getPageSize()==0&&parameter.getJoinId()==null)
        {
            return new PageResponse<>();
        }
        List<SocketLog> logs= socketLogDAO.getLogs(parameter);
        int count= socketLogDAO.getLogCount(parameter);
        return new PageResponse<>(logs,count);
    }

}
